﻿Imports BUS
Imports DTO
Public Class MonHoc

    Private Sub MonHoc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim BangMH As New DataTable
        Dim mhbus As New MonHocBUS

        BangMH = mhbus.LayBang()
        Me.gridDSMH.DataSource = BangMH
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim mhBus As New MonHocBUS
        Dim mhDTO As New MonHocDTO

        mhDTO.TenMH = Me.txtTenMH.Text

        For i As Integer = 0 To mhDTO.TenMH.Length - 1
            If Char.IsNumber(mhDTO.TenMH(i)) Then
                MsgBox("Dữ liệu không hợp lệ", MsgBoxStyle.Exclamation, "warning")
                Exit Sub
            End If
        Next

        mhBus.Them(mhDTO)

        Dim bangMH As New DataTable
        bangMH = mhBus.LayBang()
        Me.gridDSMH.DataSource = bangMH
    End Sub


    Private Sub gridDSMH_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridDSMH.SelectionChanged
        If (Me.gridDSMH.SelectedRows.Count > 0) Then
            Me.txtTenMH.Text = Me.gridDSMH.SelectedRows(0).Cells(2).Value
        End If
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Dim mhBUS As New MonHocBUS
        Dim mhDTO As New MonHocDTO
        mhDTO.MaMH = Me.gridDSMH.CurrentRow.Cells(1).Value
        mhDTO.TenMH = Me.gridDSMH.CurrentRow.Cells(2).Value
        For i As Integer = 0 To mhDTO.TenMH.Length - 1
            If Char.IsNumber(mhDTO.TenMH(i)) Then
                MsgBox("Dữ liệu không hợp lệ", MsgBoxStyle.Exclamation, "warning")
                Exit Sub
            End If
        Next
        mhBUS.SuaMonHoc(mhDTO)

        Dim bangMH As New DataTable
        bangMH = mhBUS.LayBang()
        gridDSMH.DataSource = bangMH
    End Sub

End Class
